package com.example.a022.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 022 on 2018/9/3.
 */

public class HomeFragment extends Fragment {
    private View view;
    private List<String> data;
    private GridView gridView;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.home_fragment,null);
        data = new ArrayList<>();
        init();

        data.add("http://soso3.gtimg.cn/sosopic/0/11129365531347748413/640");
        data.add("https://img01.sogoucdn.com/app/a/100520093/ca86e620b9e623ff-e7ae36db714776c0-b0158348187351632005e109f7faff29.jpg");
        data.add("http://bj-feiyuantu.oss-cn-beijing.aliyuncs.com/creative/vcg/veer/800water/veer-108434082.jpg");
        data.add("https://img02.sogoucdn.com/app/a/100520093/2ad11b094c93197d-4afaf786506af54b-9fd277aea03c8387ebd35dcfba4ba3dd.jpg");
        data.add("https://img03.sogoucdn.com/app/a/100520093/10e8b9550acde0b8-459f14f6a089053d-e879bbcb128a7b240716f9531571fc2c.jpg");
        data.add("https://i03piccdn.sogoucdn.com/cef9209b75d03a5e");
        data.add("http://soso3.gtimg.cn/sosopic/0/11129365531347748413/640");
        data.add("https://img01.sogoucdn.com/app/a/100520093/ca86e620b9e623ff-e7ae36db714776c0-b0158348187351632005e109f7faff29.jpg");
        data.add("http://bj-feiyuantu.oss-cn-beijing.aliyuncs.com/creative/vcg/veer/800water/veer-108434082.jpg");
        data.add("https://img02.sogoucdn.com/app/a/100520093/2ad11b094c93197d-4afaf786506af54b-9fd277aea03c8387ebd35dcfba4ba3dd.jpg");
        data.add("https://img03.sogoucdn.com/app/a/100520093/10e8b9550acde0b8-459f14f6a089053d-e879bbcb128a7b240716f9531571fc2c.jpg");
        data.add("https://i03piccdn.sogoucdn.com/cef9209b75d03a5e");
        data.add("http://soso3.gtimg.cn/sosopic/0/11129365531347748413/640");
        data.add("https://img01.sogoucdn.com/app/a/100520093/ca86e620b9e623ff-e7ae36db714776c0-b0158348187351632005e109f7faff29.jpg");
        data.add("http://bj-feiyuantu.oss-cn-beijing.aliyuncs.com/creative/vcg/veer/800water/veer-108434082.jpg");
        data.add("https://img02.sogoucdn.com/app/a/100520093/2ad11b094c93197d-4afaf786506af54b-9fd277aea03c8387ebd35dcfba4ba3dd.jpg");
        data.add("https://img03.sogoucdn.com/app/a/100520093/10e8b9550acde0b8-459f14f6a089053d-e879bbcb128a7b240716f9531571fc2c.jpg");
        data.add("https://i03piccdn.sogoucdn.com/cef9209b75d03a5e");
        data.add("http://soso3.gtimg.cn/sosopic/0/11129365531347748413/640");
        data.add("https://img01.sogoucdn.com/app/a/100520093/ca86e620b9e623ff-e7ae36db714776c0-b0158348187351632005e109f7faff29.jpg");
        data.add("http://bj-feiyuantu.oss-cn-beijing.aliyuncs.com/creative/vcg/veer/800water/veer-108434082.jpg");
        data.add("https://img02.sogoucdn.com/app/a/100520093/2ad11b094c93197d-4afaf786506af54b-9fd277aea03c8387ebd35dcfba4ba3dd.jpg");
        data.add("https://img03.sogoucdn.com/app/a/100520093/10e8b9550acde0b8-459f14f6a089053d-e879bbcb128a7b240716f9531571fc2c.jpg");
        data.add("https://i03piccdn.sogoucdn.com/cef9209b75d03a5e");


        gridView.setAdapter(new FragmentAdapter(getActivity(),data));

        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
               // Intent intent = new Intent(getActivity(),PorductDetailsActivity.class);
                Intent intent = new Intent(getActivity(),DetailActivity.class);
                startActivity(intent);
            }
        });

        return view;

    }

    private void init() {
        gridView = (GridView) view.findViewById(R.id.gridView);
    }
}
